#include <pthread.h>

int pthread_attr_init(pthread_attr_t *attr);
int pthread_attr_destroy(phtread_attr_t *attr);

/*
 * RETURN VALUE
 *      On success, these functions return 0; on error, they retrun a nonzero
 *      error number.
 *
 * ERRORS
 *      POSIX.1-2001 documents an ENOMEM error for pthread_attr_init(); on
 *      Linux these functions always succeed (but portable and future-proof
 *      applications should nevertheless handle a possible error return).
 */




#include <pthread.h>

int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
int pthread_attr_getdetachstate(pthread_attr_t *attr, int *detachstate);

/* RETURN VALUE
 *      ON success, these functions return 0; on error, they return a nonzero
 *      error number.
 *
 * ERRORS
 *      pthread_attr_setdetachstate() can fail with the following error:
 *      EINVAL  An invalid value was specified in detachstate.
 */




#include <pthread.h>

int pthraed_attr_setstack(pthread_attr_t *attr, 
                          void *stackaddr, size_t stacksize);
int pthread_attr_getstack(pthread_attr_t *attr,
                          void **stackaddr, size_t *stacksize);

/* RETURN VALUE
 *      On success, these functions return 0; on error, they return a nonzero
 *      error number.
 *
 * ERRORS
 *      pthread_attr_setstack() can fail with the following error:
 *
 *      EINVAL  stacksize is less than PTHREAD_STACK_MIN (16384) bytes. On some
 *              systems, this error may also occur if stackaddr or 
 *              stackaddr + stacksize is not suitbably aligned.
 *      
 *      POSIX.1-2001 also documents an EACCES error if the stack area described
 *      by stackaddr and stacksize is not both readable and writable by the
 *      caller.
 */




#include <pthread.h>

int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
int pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize);

/* RETURN VALUE
 *      On success, these functions return 0; on error, they return a nonzero
 *      error number.
 *
 * ERRORS
 *      pthread_attr_setstacksize() can fail with the following error:
 *
 *      EINVAL  The stack size is less than PTHREAD_STACK_MIN (16384) bytes.
 *      
 *      On some systems, pthread_attr_setstacksize() can fail with the error
 *      EINVAL if stacksize is not a multiple of the system page size.
 */




#include <pthread.h>

int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
int pthread_attr_getguardsize(pthread_attr_t *attr, size_t *guardsize);

/* RETURN VALUE
 *      On success, these functions return 0; on error, they return a nonzero
 *      error number.
 *
 * ERRORS
 *      POSIX.1-2001 documents an EINVAL error if attr or guardsize is invalid.
 *      On Linux these functions always succeed (but portable and future-proof
 *      applications should nevertheless handle a possible error return).
 */




#include <pthread.h>

int pthread_mutexattr_init(pthread_mutexattr_t *attr);

int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);

int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind);

int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *kind);

/* DESCRIPTION
 *      LinuxThreads supports only one mutex attribute: the mutex kind, which
 *      is either 
 *      PTHREAD_MUTEX_FAST_NP for 'fast' mutexes,
 *      PTHREAD_MUTEX_RECURSIVE_NP for 'recursive' mutexes, or
 *      PTHREAD_MUTEX_ERRORCHECK_NP for 'error checking' mutexs.
 *      As the NP suffix indicates, this is a non-portable extension to the
 *      POSIX standard and should not be employed in portable programs.
 *
 * RETURN VALUE
 *      pthread_mutexattr_init, pthread_mutexattr_destroy and
 *      pthread_mutexattr_gettype always return 0.
 *      
 *      pthread_mutexattr_settype returns 0 on success and a non-zero error
 *      code on error.
 *
 * ERRORS
 *      On error, pthread_mutexattr_settype returns the following error code:
 *      
 *      EINVAL  kind is neither PTHREAD_MUTEX_FAST_NP nor
 *              PTHREAD_MUTEX_RECURSIVE_NP nor PTHREAD_ERRORCHECK_NP.
 */




#include <pthread.h>

int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict attr,
                                 int *restrict pshared);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared);

/* DESCRIPTION
 *      The process-shared attribute is set to PTHREAD_PROCESS_SHARED to
 *      permit a mutex to be operated upon by any thread that has access
 *      to the memory where the mutex is allocated, even if the mutex is
 *      allocated in memory that is shared by multiple processes. If the
 *      process-shared attribute is PTHREAD_PROCESS_PRIVATE, the mutex
 *      shall only be operated upon by threads created within the same
 *      process as the thread that initialized the mutex; if threads of
 *      differing processes attempt to operate on such a mutex, the behavior
 *      is undefined. The default value of the attribute shall be
 *      PTHREAD_PROCESS_PRIVATE.
 *
 * RETURN VALUE
 *      Upon successful completion, pthread_mutexattr_setpshared() shall
 *      return zero; otherwise, an error number shall be returned to
 *      indicate the error.
 *
 *      Upon successful completion, pthread_mutexattr_getpshared() shall
 *      return zero and store the value of the process-shared attribute
 *      of attr into the object referenced by pshared parameter. Otherwise,
 *      an error number shall be returned to indicate the error.
 *
 * ERRORS
 *      The pthread_mutexattr_getpshared() and pthread_mutexattr_setpshared()
 *      functions may fail if:
 *
 *      EINVAL  The value specified by attr is invalid.
 *
 *      The pthread_mutexattr_setpshared() function may fail if:
 *
 *      EINVAL  The new value specified for the attribute is outside the
 *              range of legal values for that attribute.
 *
 *      These functions shall not return an error code of [EINTR].
 */




#include <pthread.h>

int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict attr,
                                int *restrict robust);
int pthread_mutexattr_setrobust(pthread_mutexattr_t *attr, int robust);

/* DESCRIPTION
 *      The pthread_mutexattr_getrobust() and pthread_mutexattr_setrobust()
 *      functions, repectively, shall get and set the mutex robust attribute.
 *      This attribute is set in the robust parameter. Valid values for
 *      robust include:
 *
 *      PTHREAD_MUTEX_STALLED
 *      PTHREAD_MUTEX_ROBUST
 *
 * RETURN VALUE
 *      Upon successful completion, the pthread_mutexattr_getrobust() function
 *      shall return zero and store the value of the robust attribute of attr
 *      into the object referenced by the robust parameter. Otherwise, an
 *      error value shall be returned to indicate the error.
 *
 *      If successful, the pthread_mutexattr_setrobust() funcation shall
 *      return zero; otherwise, an error number shall be returned to indicate
 *      the error.
 *
 * ERRORS
 *      The pthread_mutexattr_setrobust() function shall fail if:
 *
 *      EINVAL  The value of robust is invalid.
 *
 *      These functions shall not return an error code of [EINTR].
 */




#include <pthread.h>

int pthread_mutex_consistent(pthread_mutex_t *mutex);

/* RETURN VALUE
 *      Upon successful completion, the pthread_mutex_consistent() function
 *      shall return zero. Otherwise, an error value shall be returned to
 *      indicate the error.
 *
 * ERRORS
 *      The pthread_mutex_consistent() function shall fail if:
 *
 *      EINVAL
 *          The mutex object referenced by mutex is not robust or does not
 *          protect an inconsistent state. These functions shall not return
 *          an error code of [EINTR].
 */
